﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.WeixinMP.Models;
using Microhard.Core.DBUtility;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace Microhard.WeixinMP.Impls
{
    public class WXCookieCacheOperator : ICacheOperator<WeixinCookie>
    {
        private ICacheManager cm = CacheFactory.GetCacheManager("mpcookie");

        public void UpdateCache(string key, WeixinCookie newModel)
        {
            cm.Add(key, newModel, CacheItemPriority.Normal, null, new NeverExpired());
        }

        public WeixinCookie GetFromCache(string key)
        {
            WeixinCookie rtn = new WeixinCookie();
            if (string.IsNullOrEmpty(key))
                return rtn;
            rtn = cm.GetData(key) as WeixinCookie;
            return rtn;
        }

        public void RemoveFormCache(List<string> keys)
        {
            if (keys == null)
                return;
            foreach (var k in keys)
            {
                cm.Remove(k);
            }
        }

        public void RefreshCache()
        {
            throw new NotImplementedException();
        }
    }
}
